package com.aaa.three.service.impl;

import com.aaa.three.entity.AddDate;
import com.aaa.three.entity.DoctorPrice;
import com.aaa.three.mapper.SchduleDepartmentMapper;
import com.aaa.three.pojo.domain.AdminDept;
import com.aaa.three.pojo.domain.AdminInfo;
import com.aaa.three.pojo.domain.AdminOffice;
import com.aaa.three.pojo.domain.AdminRole;
import com.aaa.three.result.AjaxResult;
import com.aaa.three.service.SchduleDepartmentService;
import com.aaa.three.sysconst.LoginConst;
import com.aaa.three.util.QueryDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

/**
 * @PACKAGE_NAME: com.aaa.three.service.impl
 * @NAME: schduleDepartmentServiceImpl
 * @USER: Tprairie
 * @DATE: 2022/2/17
 * @PROJECT_NAME: three
 */
@Service
public class SchduleDepartmentServiceImpl implements SchduleDepartmentService {
    @Autowired
    private SchduleDepartmentMapper schduleDepartmentMapper;
    @Autowired
    private HttpSession session;
    @Override
    public AjaxResult outDeparment() {
        AdminInfo attribute = (AdminInfo) session.getAttribute(LoginConst.EMP_IN_SESSION);
        AdminDept dept = attribute.getDept();
        AdminRole role = attribute.getRole();
        Integer id = role.getId();
        if(id==4){
            Integer aid= attribute.getId();
            AdminOffice office = attribute.getOffice();
            Integer oid = office.getId();
            List<AdminOffice> part = schduleDepartmentMapper.outDeparment(aid,oid);
            return AjaxResult.success(part);
        }
        List<AdminOffice> depar= schduleDepartmentMapper.department(dept);
        return AjaxResult.success(depar);
    }

    @Override
    public AjaxResult listDoctor(Integer id) {
        List<AdminInfo> adminInfos = schduleDepartmentMapper.listDoctor(id);
        return AjaxResult.success(adminInfos);
    }

    @Override
    public AjaxResult getAddschedule() {
        AdminInfo attribute = (AdminInfo) session.getAttribute(LoginConst.EMP_IN_SESSION);
        AdminDept dept = attribute.getDept();
        AdminRole role = attribute.getRole();
        Integer id = role.getId();
        if(id==4){
            Integer aid= attribute.getId();
            AdminOffice office = attribute.getOffice();
            Integer oid = office.getId();
            List<AdminOffice> part = schduleDepartmentMapper.outDeparment(aid,oid);
            String query = QueryDate.query(1);
            List<AddDate> listdate=schduleDepartmentMapper.getAddschedule(query);
            List<DoctorPrice> listprice=schduleDepartmentMapper.getAddPrice();
            HashMap<Object, Object> map = new HashMap<>();
            map.put("de",part);
            map.put("da",listdate);
            map.put("pr",listprice);
            return AjaxResult.success(map);
        }
        List<AdminOffice> depar= schduleDepartmentMapper.department(dept);
        String query = QueryDate.query(1);
        List<AddDate> listdate=schduleDepartmentMapper.getAddschedule(query);
        List<DoctorPrice> listprice=schduleDepartmentMapper.getAddPrice();
        HashMap<Object, Object> map = new HashMap<>();
        map.put("de",depar);
        map.put("da",listdate);
        map.put("pr",listprice);
        return AjaxResult.success(map);
    }
}
